package com.poh.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.poh.mapper.UserMapper;
import com.poh.pojo.User;
import com.poh.pojo.query.UserQuery;

import com.poh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;


    public User userLogin(String userName, String passWord) {
        return userMapper.userLogin(userName, passWord);
    }

    @Override
    public int updateImgByUserId(int userId, String userImg) {
        return userMapper.updateImgByUserId(userId, userImg);
    }

    @Override
    public int studentAddCourse(int userId, int courseId) {
        return userMapper.studentAddCourse(userId, courseId);
    }

    @Override
    public List<User> getStudentByCourseId(int courseId) {
        return userMapper.getStudentByCourseId(courseId);
    }

    @Override
    public int deleteUserById(int userId, int courseId) {
        return userMapper.deleteUserById(userId, courseId);
    }

    @Override
    public List<User> queryStudentLikeStudentName(int courseId, String userName) {
        return userMapper.queryStudentLikeStudentName(courseId, userName);
    }

    @Override
    public int addStudentToCourse(int userId, int courseId) {
        return userMapper.addStudentToCourse(userId, courseId);
    }

    @Override
    public int getCourseIdByInvitationCode(String invitationCode) {
        return userMapper.getCourseIdByInvitationCode(invitationCode);
    }

    @Override
    public String getUserNameById(int userId) {
        return userMapper.getUserNameById(userId);
    }

    @Override
    public PageInfo<User> listUserByName(UserQuery userQuery) {
        PageHelper.startPage(userQuery.getPageNum(),userQuery.getPageSize());
        return new PageInfo<User>(userMapper.listUserByName(userQuery));
    }

    @Override
    public int addUser(User user) {
        user.setUserImg("109951166719242341.jpg");
        return userMapper.addUser(user);
    }

    @Override
    public int updateUserById(User user) {
        return userMapper.updateUserById(user);
    }

    @Override
    public List<User> getAllStudent() {
        return userMapper.getAllStudent();
    }

    @Override
    public User getUserById(int userId) {
        return userMapper.getUserById(userId);
    }


}
